#include "precompile.h"

#include "Panes.h"
#include "Pane.h"
#include "form/IPane.h"
#include "FreeIdentifier.h"

Panes::Panes()
{
}

Panes::~Panes()
{
}

IPane* Panes::CreatePane()
{
	IPane* newpane = NewPane();
	if (!newpane)
		return  NULL;

	return  newpane;
}

uint32 Panes::GetPanes(PaneList& panes) const
{
	PaneDictionary::const_iterator itbegin = m_panes.begin();
	PaneDictionary::const_iterator itend = m_panes.end();
	for (; itbegin != itend; ++itbegin)
	{
		panes.push_back(itbegin->second.P());
	}
	return panes.size();
}

//////////////////////////////////////////////////////////////////////////
//private methods
IPane* Panes::NewPane()
{
	sys::ObjectPtr objPane;
	VRVERIFY(objPane.CreateObject(CLSID_Pane));
	if (objPane.IsNotNull())
	{
		FreeIdentifier<sys::ObjectPtr> identifier(PANEID_RESERVEID_FIRST,PANEID_RESERVEID_LAST,m_panes);
		uint32 nGlobalID = identifier.GetUnique(objPane);
		if (nGlobalID == ERROR_ID)
			return NULL;

		sys::InterfacePtr<IPane> pIFPane(objPane);
		pIFPane->SetID(nGlobalID);
		m_panes[nGlobalID] = objPane;
		return pIFPane;
	}
	return NULL;
}